<%--
  Created by IntelliJ IDEA.
  User: Administrator_
  Date: 2020/8/12
  Time: 20:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>测试</title>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/"/>
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">
        $(function () {
            $("#btn1").click(function () {
                $.ajax({
                    "url": "send/array/one.html",
                    "type": "post",
                    "data": {
                        "array": [5, 8, 12]
                    },
                    "datatype": "text",
                    "success": function (response) {
                        alert(response);
                    },
                    "error": function (response) {
                        alert(response);
                    }
                });
            });

            //btn2
            //此方式可以在浏览器看到发送的请求体是Request Payload(请求负载)
            $("#btn2").click(function () {
                //准备要发送的数据
                var array = [5, 8, 12];
                //将JSON数组转换成JSON字符串
                var arrayStr = JSON.stringify(array);
                $.ajax({
                    url: "send/array/two.html",         //请求目标资源地址
                    type: "post",                       //请求方式
                    data: arrayStr,                     //发送的请求参数
                    dataType: "text",                   //表示如何对待服务器返回的数据
                    contentType: "application/json;charset=UTF-8",  //告诉服务器端当前请求的请求体是JSON格式
                    success: function (response) {
                        alert(response);
                    },
                    error: function (response) {
                        alert(response);
                    }

                });
            });
            //btn4
            //使用ResultEntity，统一返回的格式
            $("#btn4").click(function () {
                var student = {
                    "name": "Fall",
                    "id": 21,
                    "address": {
                        "province": "浙江",
                        "city": "宁波"
                    },
                    "subjects": [
                        {
                            "subjectName": "Java",
                            "score": 96
                        },
                        {
                            "subjectName": "Data Struct",
                            "score": 93
                        }
                    ],
                    "map": {
                        "key1": "value1",
                        "key2": "value2"
                    }
                };   //student end
                var studentStr = JSON.stringify(student);
                $.ajax({
                    url: "send/compose/object.json",         //请求目标资源地址
                    type: "post",                       //请求方式
                    data: studentStr,                     //发送的请求参数
                    dataType: "json",                   //表示如何对待服务器返回的数据
                    contentType: "application/json;charset=UTF-8",  //告诉服务器端当前请求的请求体是JSON格式
                    success: function (response) {
                        console.log(response);
                    },
                    error: function (response) {
                        console.log(response);
                    }
                });

            });//btn4
            $("#btn5").click(function () {
                layer.msg("hello")
            });//btn5
        });
    </script>
</head>
<body>
        <a href="test/ssm.html">测试ssm</a>
        <br>
        <button id="btn1">测试ajax</button>
        <br>
        <button id="btn2">测试ajax2</button>
        <br>
        <button id="btn4">测试ajax3</button>
        <br>
        <button id="btn5">测试弹框</button>
        <br>
        <br>
        <a href="admin/do/login.html">点击跳转</a>
        <br><br>
        <br><br>
        <jsp:forward page="/admin/login/page.html"></jsp:forward>
</body>
</html>
